// src/store/index.js
import { createStore } from 'vuex';
import createPersistedState from 'vuex-persistedstate';

export default createStore({
  state: {
    count: 0,
    menuList: [],
    sessionId: '',
    operatorName: ''
  },
  mutations: {
    increment (state) {
      state.count++;
    },
    setMenuList (state, menuList) {
      console.log(menuList, '==>');
      state.menuList = menuList;
    },
    setSessionId (state, sessionId) {
      state.sessionId = sessionId;
    },
    setOperatorName (state, name) {
      state.operatorName = name;
    }
  },
  actions: {
    increment ({ commit }) {
      commit('increment');
    },

  },
  getters: {
    count: state => state.count
  },
  plugins: [
    createPersistedState({
      // 配置项
      storage: window.localStorage, // 存储方式，默认为 localStorage
      paths: ['count', 'menuList', 'sessionId', 'operatorName'], // 需要持久化的 state 路径
    }),
  ],
});